1 <?php
2 // This script and data application were generated
by AppGini 5.72
3 // Download AppGini
for free from https://bigprof.com/appgini/download/
4
5     
/* Configuration */
6     
/*************************************/
7
8         $pcConfig = array(
9             
'schools' => array(
10             ),
11             
'departments' => array(
12                 
'school' => array(
13                     
'parent-table' => 'schools',
14                     
'parent-primary-key' => 'id',
15                     
'child-primary-key' => 'id',
16                     
'child-primary-key-index' => 0,
17                     
'tab-label' => 'Departments',
18                     
'auto-close' => true,
19                     
'table-icon' => 'resources/table_icons/chart_organisation.png',
20                     
'display-refresh' => true,
21                     
'display-add-new' => true,
22                     
'forced-where' => '',
23                     
'display-fields' => array(1 => 'Name', 2 => 'School'),
24                     
'display-field-names' => array(1 => 'name', 2 => 'school'),
25                     
'sortable-fields' => array(0 => '`departments`.`id`', 1 => 2, 2 => '`schools1`.`name`'),
26                     
'records-per-page' => 10,
27                     
'default-sort-by' => false,
28                     
'default-sort-direction' => 'asc',
29                     
'open-detail-view-on-click' => true,
30                     
'display-page-selector' => true,
31                     
'show-page-progress' => true,
32                     
'template' => 'children-departments',
33                     
'template-printable' => 'children-departments-printable',
34                     
'query' => "SELECT `departments`.`id` as 'id', `departments`.`name` as 'name', IF( CHAR_LENGTH(`schools1`.`name`), CONCAT_WS('', `schools1`.`name`), '') as 'school' FROM `departments` LEFT JOIN `schools` as schools1 ON `schools1`.`id`=`departments`.`school` "
35                 )
36             ),
37             
'class_time_table' => array(
38                 
'school' => array(
39                     
'parent-table' => 'schools',
40                     
'parent-primary-key' => 'id',
41                     
'child-primary-key' => 'id',
42                     
'child-primary-key-index' => 0,
43                     
'tab-label' => 'Class time table',
44                     
'auto-close' => true,
45                     
'table-icon' => 'resources/table_icons/blackboard_drawing.png',
46                     
'display-refresh' => true,
47                     
'display-add-new' => true,
48                     
'forced-where' => '',
49                     
'display-fields' => array(1 => 'Day', 2 => ' Time Start', 3 => 'Time End', 4 => 'Unit code', 5 => 'Venue', 6 => 'School', 7 => 'Department', 8 => 'Year of study'),
50                     
'display-field-names' => array(1 => 'day', 2 => 'time_start', 3 => 'time_end', 4 => 'unit_code', 5 => 'venue', 6 => 'school', 7 => 'department', 8 => 'year_of_study'),
51                     
'sortable-fields' => array(0 => '`class_time_table`.`id`', 1 => 2, 2 => '`class_time_table`.`time_start`', 3 => '`class_time_table`.`time_end`', 4 => 5, 5 => 6, 6 => '`schools1`.`name`', 7 => '`departments1`.`name`', 8 => 9),
52                     
'records-per-page' => 10,
53                     
'default-sort-by' => false,
54                     
'default-sort-direction' => 'asc',
55                     
'open-detail-view-on-click' => true,
56                     
'display-page-selector' => true,
57                     
'show-page-progress' => true,
58                     
'template' => 'children-class_time_table',
59                     
'template-printable' => 'children-class_time_table-printable',
60                     
'query' => "SELECT `class_time_table`.`id` as 'id', `class_time_table`.`day` as 'day', TIME_FORMAT(`class_time_table`.`time_start`, '%r') as 'time_start', TIME_FORMAT(`class_time_table`.`time_end`, '%r') as 'time_end', `class_time_table`.`unit_code` as 'unit_code', `class_time_table`.`venue` as 'venue', IF( CHAR_LENGTH(`schools1`.`name`), CONCAT_WS('', `schools1`.`name`), '') as 'school', IF( CHAR_LENGTH(`departments1`.`name`), CONCAT_WS('', `departments1`.`name`), '') as 'department', `class_time_table`.`year_of_study` as 'year_of_study' FROM `class_time_table` LEFT JOIN `schools` as schools1 ON `schools1`.`id`=`class_time_table`.`school` LEFT JOIN `departments` as departments1 ON `departments1`.`id`=`class_time_table`.`department` "
61                 ),
62                 
'department' => array(
63                     
'parent-table' => 'departments',
64                     
'parent-primary-key' => 'id',
65                     
'child-primary-key' => 'id',
66                     
'child-primary-key-index' => 0,
67                     
'tab-label' => 'Class time table',
68                     
'auto-close' => true,
69                     
'table-icon' => 'resources/table_icons/blackboard_drawing.png',
70                     
'display-refresh' => true,
71                     
'display-add-new' => true,
72                     
'forced-where' => '',
73                     
'display-fields' => array(1 => 'Day', 2 => ' Time Start', 3 => 'Time End', 4 => 'Unit code', 5 => 'Venue', 6 => 'School', 7 => 'Department', 8 => 'Year of study'),
74                     
'display-field-names' => array(1 => 'day', 2 => 'time_start', 3 => 'time_end', 4 => 'unit_code', 5 => 'venue', 6 => 'school', 7 => 'department', 8 => 'year_of_study'),
75                     
'sortable-fields' => array(0 => '`class_time_table`.`id`', 1 => 2, 2 => '`class_time_table`.`time_start`', 3 => '`class_time_table`.`time_end`', 4 => 5, 5 => 6, 6 => '`schools1`.`name`', 7 => '`departments1`.`name`', 8 => 9),
76                     
'records-per-page' => 10,
77                     
'default-sort-by' => false,
78                     
'default-sort-direction' => 'asc',
79                     
'open-detail-view-on-click' => true,
80                     
'display-page-selector' => true,
81                     
'show-page-progress' => true,
82                     
'template' => 'children-class_time_table',
83                     
'template-printable' => 'children-class_time_table-printable',
84                     
'query' => "SELECT `class_time_table`.`id` as 'id', `class_time_table`.`day` as 'day', TIME_FORMAT(`class_time_table`.`time_start`, '%r') as 'time_start', TIME_FORMAT(`class_time_table`.`time_end`, '%r') as 'time_end', `class_time_table`.`unit_code` as 'unit_code', `class_time_table`.`venue` as 'venue', IF( CHAR_LENGTH(`schools1`.`name`), CONCAT_WS('', `schools1`.`name`), '') as 'school', IF( CHAR_LENGTH(`departments1`.`name`), CONCAT_WS('', `departments1`.`name`), '') as 'department', `class_time_table`.`year_of_study` as 'year_of_study' FROM `class_time_table` LEFT JOIN `schools` as schools1 ON `schools1`.`id`=`class_time_table`.`school` LEFT JOIN `departments` as departments1 ON `departments1`.`id`=`class_time_table`.`department` "
85                 )
86             ),
87             
'exam_time_table' => array(
88                 
'school' => array(
89                     
'parent-table' => 'schools',
90                     
'parent-primary-key' => 'id',
91                     
'child-primary-key' => 'id',
92                     
'child-primary-key-index' => 0,
93                     
'tab-label' => 'Exam time table',
94                     
'auto-close' => true,
95                     
'table-icon' => 'resources/table_icons/books.png',
96                     
'display-refresh' => true,
97                     
'display-add-new' => true,
98                     
'forced-where' => '',
99                     
'display-fields' => array(1 => 'Date', 2 => 'Time Start', 3 => 'Time End', 4 => 'Unit code', 5 => 'Venue', 6 => 'School', 7 => 'Department', 8 => 'Year of study'),
100                     
'display-field-names' => array(1 => 'date', 2 => 'time_start', 3 => 'time_end', 4 => 'unit_code', 5 => 'venue', 6 => 'school', 7 => 'department', 8 => 'year_of_study'),
101                     
'sortable-fields' => array(0 => '`exam_time_table`.`id`', 1 => '`exam_time_table`.`date`', 2 => '`exam_time_table`.`time_start`', 3 => '`exam_time_table`.`time_end`', 4 => 5, 5 => 6, 6 => '`schools1`.`name`', 7 => '`departments1`.`name`', 8 => 9),
102                     
'records-per-page' => 10,
103                     
'default-sort-by' => false,
104                     
'default-sort-direction' => 'asc',
105                     
'open-detail-view-on-click' => true,
106                     
'display-page-selector' => true,
107                     
'show-page-progress' => true,
108                     
'template' => 'children-exam_time_table',
109                     
'template-printable' => 'children-exam_time_table-printable',
110                     
'query' => "SELECT `exam_time_table`.`id` as 'id', if(`exam_time_table`.`date`,date_format(`exam_time_table`.`date`,'%m/%d/%Y'),'') as 'date', TIME_FORMAT(`exam_time_table`.`time_start`, '%r') as 'time_start', TIME_FORMAT(`exam_time_table`.`time_end`, '%r') as 'time_end', `exam_time_table`.`unit_code` as 'unit_code', `exam_time_table`.`venue` as 'venue', IF( CHAR_LENGTH(`schools1`.`name`), CONCAT_WS('', `schools1`.`name`), '') as 'school', IF( CHAR_LENGTH(`departments1`.`name`), CONCAT_WS('', `departments1`.`name`), '') as 'department', `exam_time_table`.`year_of_study` as 'year_of_study' FROM `exam_time_table` LEFT JOIN `schools` as schools1 ON `schools1`.`id`=`exam_time_table`.`school` LEFT JOIN `departments` as departments1 ON `departments1`.`id`=`exam_time_table`.`department` "
111                 ),
112                 
'department' => array(
113                     
'parent-table' => 'departments',
114                     
'parent-primary-key' => 'id',
115                     
'child-primary-key' => 'id',
116                     
'child-primary-key-index' => 0,
117                     
'tab-label' => 'Exam time table',
118                     
'auto-close' => true,
119                     
'table-icon' => 'resources/table_icons/books.png',
120                     
'display-refresh' => true,
121                     
'display-add-new' => true,
122                     
'forced-where' => '',
123                     
'display-fields' => array(1 => 'Date', 2 => 'Time Start', 3 => 'Time End', 4 => 'Unit code', 5 => 'Venue', 6 => 'School', 7 => 'Department', 8 => 'Year of study'),
124                     
'display-field-names' => array(1 => 'date', 2 => 'time_start', 3 => 'time_end', 4 => 'unit_code', 5 => 'venue', 6 => 'school', 7 => 'department', 8 => 'year_of_study'),
125                     
'sortable-fields' => array(0 => '`exam_time_table`.`id`', 1 => '`exam_time_table`.`date`', 2 => '`exam_time_table`.`time_start`', 3 => '`exam_time_table`.`time_end`', 4 => 5, 5 => 6, 6 => '`schools1`.`name`', 7 => '`departments1`.`name`', 8 => 9),
126                     
'records-per-page' => 10,
127                     
'default-sort-by' => false,
128                     
'default-sort-direction' => 'asc',
129                     
'open-detail-view-on-click' => true,
130                     
'display-page-selector' => true,
131                     
'show-page-progress' => true,
132                     
'template' => 'children-exam_time_table',
133                     
'template-printable' => 'children-exam_time_table-printable',
134                     
'query' => "SELECT `exam_time_table`.`id` as 'id', if(`exam_time_table`.`date`,date_format(`exam_time_table`.`date`,'%m/%d/%Y'),'') as 'date', TIME_FORMAT(`exam_time_table`.`time_start`, '%r') as 'time_start', TIME_FORMAT(`exam_time_table`.`time_end`, '%r') as 'time_end', `exam_time_table`.`unit_code` as 'unit_code', `exam_time_table`.`venue` as 'venue', IF( CHAR_LENGTH(`schools1`.`name`), CONCAT_WS('', `schools1`.`name`), '') as 'school', IF( CHAR_LENGTH(`departments1`.`name`), CONCAT_WS('', `departments1`.`name`), '') as 'department', `exam_time_table`.`year_of_study` as 'year_of_study' FROM `exam_time_table` LEFT JOIN `schools` as schools1 ON `schools1`.`id`=`exam_time_table`.`school` LEFT JOIN `departments` as departments1 ON `departments1`.`id`=`exam_time_table`.`department` "
135                 )
136             ),
137             
'personal_time_table' => array(
138             ),
139             
'student_details' => array(
140                 
'school' => array(
141                     
'parent-table' => 'schools',
142                     
'parent-primary-key' => 'id',
143                     
'child-primary-key' => 'id',
144                     
'child-primary-key-index' => 0,
145                     
'tab-label' => 'Personal details',
146                     
'auto-close' => true,
147                     
'table-icon' => 'resources/table_icons/administrator.png',
148                     
'display-refresh' => true,
149                     
'display-add-new' => true,
150                     
'forced-where' => '',
151                     
'display-fields' => array(1 => 'Full name', 2 => 'School', 3 => 'Department', 4 => 'Year of study', 5 => 'Reg no'),
152                     
'display-field-names' => array(1 => 'full_name', 2 => 'school', 3 => 'department', 4 => 'year_of_study', 5 => 'reg_no'),
153                     
'sortable-fields' => array(0 => '`student_details`.`id`', 1 => 2, 2 => '`schools1`.`name`', 3 => '`departments1`.`name`', 4 => 5, 5 => 6),
154                     
'records-per-page' => 10,
155                     
'default-sort-by' => false,
156                     
'default-sort-direction' => 'asc',
157                     
'open-detail-view-on-click' => true,
158                     
'display-page-selector' => true,
159                     
'show-page-progress' => true,
160                     
'template' => 'children-student_details',
161                     
'template-printable' => 'children-student_details-printable',
162                     
'query' => "SELECT `student_details`.`id` as 'id', `student_details`.`full_name` as 'full_name', IF( CHAR_LENGTH(`schools1`.`name`), CONCAT_WS('', `schools1`.`name`), '') as 'school', IF( CHAR_LENGTH(`departments1`.`name`), CONCAT_WS('', `departments1`.`name`), '') as 'department', `student_details`.`year_of_study` as 'year_of_study', `student_details`.`reg_no` as 'reg_no' FROM `student_details` LEFT JOIN `schools` as schools1 ON `schools1`.`id`=`student_details`.`school` LEFT JOIN `departments` as departments1 ON `departments1`.`id`=`student_details`.`department` "
163                 ),
164                 
'department' => array(
165                     
'parent-table' => 'departments',
166                     
'parent-primary-key' => 'id',
167                     
'child-primary-key' => 'id',
168                     
'child-primary-key-index' => 0,
169                     
'tab-label' => 'Personal details',
170                     
'auto-close' => true,
171                     
'table-icon' => 'resources/table_icons/administrator.png',
172                     
'display-refresh' => true,
173                     
'display-add-new' => true,
174                     
'forced-where' => '',
175                     
'display-fields' => array(1 => 'Full name', 2 => 'School', 3 => 'Department', 4 => 'Year of study', 5 => 'Reg no'),
176                     
'display-field-names' => array(1 => 'full_name', 2 => 'school', 3 => 'department', 4 => 'year_of_study', 5 => 'reg_no'),
177                     
'sortable-fields' => array(0 => '`student_details`.`id`', 1 => 2, 2 => '`schools1`.`name`', 3 => '`departments1`.`name`', 4 => 5, 5 => 6),
178                     
'records-per-page' => 10,
179                     
'default-sort-by' => false,
180                     
'default-sort-direction' => 'asc',
181                     
'open-detail-view-on-click' => true,
182                     
'display-page-selector' => true,
183                     
'show-page-progress' => true,
184                     
'template' => 'children-student_details',
185                     
'template-printable' => 'children-student_details-printable',
186                     
'query' => "SELECT `student_details`.`id` as 'id', `student_details`.`full_name` as 'full_name', IF( CHAR_LENGTH(`schools1`.`name`), CONCAT_WS('', `schools1`.`name`), '') as 'school', IF( CHAR_LENGTH(`departments1`.`name`), CONCAT_WS('', `departments1`.`name`), '') as 'department', `student_details`.`year_of_study` as 'year_of_study', `student_details`.`reg_no` as 'reg_no' FROM `student_details` LEFT JOIN `schools` as schools1 ON `schools1`.`id`=`student_details`.`school` LEFT JOIN `departments` as departments1 ON `departments1`.`id`=`student_details`.`department` "
187                 )
188             ),
189             
'notices' => array(
190             )
191         );
192
193     
/*************************************/
194     
/* End of configuration */
195
196
197     $currDir = dirname(__FILE__);
198     include(
"{$currDir}/defaultLang.php");
199     include(
"{$currDir}/language.php");
200     include(
"{$currDir}/lib.php");
201     @header(
'Content-Type: text/html; charset=' . datalist_db_encoding);
202
203     handle_maintenance();
204
205     
/**
206     *
dynamic configuration based on current user's permissions
207     * $userPCConfig array
is populated only with parent tables where the user has access to
208     * at least one child table
209     */

210     $userPCConfig = array();
211     
foreach($pcConfig as $pcChildTable => $ChildrenLookups){
212         $permChild = getTablePermissions($pcChildTable);
213         
if($permChild[2]){ // user can view records of the child table, so proceed to check children lookups
214             
foreach($ChildrenLookups as $ChildLookupField => $ChildConfig){
215                 $permParent = getTablePermissions($ChildConfig[
'parent-table']);
216                 
if($permParent[2]){ // user can view records of parent table
217                     $userPCConfig[$pcChildTable][$ChildLookupField] = $pcConfig[$pcChildTable][$ChildLookupField];
218                     
// show add new only if configured above AND the user has insert permission
219                     
if($permChild[1] && $pcConfig[$pcChildTable][$ChildLookupField]['display-add-new']){
220                         $userPCConfig[$pcChildTable][$ChildLookupField][
'display-add-new'] = true;
221                     }
else{
222                         $userPCConfig[$pcChildTable][$ChildLookupField][
'display-add-new'] = false;
223                     }
224                 }
225             }
226         }
227     }
228
229     
/* Receive, UTF-convert, and validate parameters */
230     $ParentTable = $_REQUEST[
'ParentTable']; // needed only with operation=show-children, will be validated in the processing code
231     $ChildTable = $_REQUEST[
'ChildTable'];
232         
if(!in_array($ChildTable, array_keys($userPCConfig))){
233             
/* defaults to first child table in config array if not provided */
234             $ChildTable = current(array_keys($userPCConfig));
235         }
236         
if(!$ChildTable){ die('<!-- No tables accessible to current user -->'); }
237     $SelectedID = strip_tags($_REQUEST[
'SelectedID']);
238     $ChildLookupField = $_REQUEST[
'ChildLookupField'];
239         
if(!in_array($ChildLookupField, array_keys($userPCConfig[$ChildTable]))){
240             
/* defaults to first lookup in current child config array if not provided */
241             $ChildLookupField = current(array_keys($userPCConfig[$ChildTable]));
242         }
243     $Page = intval($_REQUEST[
'Page']);
244         
if($Page < 1){
245             $Page =
1;
246         }
247     $SortBy = ($_REQUEST[
'SortBy'] != '' ? abs(intval($_REQUEST['SortBy'])) : false);
248         
if(!in_array($SortBy, array_keys($userPCConfig[$ChildTable][$ChildLookupField]['sortable-fields']), true)){
249             $SortBy = $userPCConfig[$ChildTable][$ChildLookupField][
'default-sort-by'];
250         }
251     $SortDirection = strtolower($_REQUEST[
'SortDirection']);
252         
if(!in_array($SortDirection, array('asc', 'desc'))){
253             $SortDirection = $userPCConfig[$ChildTable][$ChildLookupField][
'default-sort-direction'];
254         }
255     $Operation = strtolower($_REQUEST[
'Operation']);
256         
if(!in_array($Operation, array('get-records', 'show-children', 'get-records-printable', 'show-children-printable'))){
257             $Operation =
'get-records';
258         }
259
260     
/* process requested operation */
261     
switch($Operation){
262         
/************************************************/
263         
case 'show-children':
264             
/* populate HTML and JS content with children tabs */
265             $tabLabels = $tabPanels = $tabLoaders =
'';
266             
foreach($userPCConfig as $ChildTable => $childLookups){
267                 
foreach($childLookups as $ChildLookupField => $childConfig){
268                     
if($childConfig['parent-table'] == $ParentTable){
269                         $TableIcon = ($childConfig[
'table-icon'] ? "<img src=\"{$childConfig['table-icon']}\" border=\"0\" />" : '');
270                         $tabLabels .= sprintf(
'<li%s><a href="#panel_%s-%s" id="tab_%s-%s" data-toggle="tab">%s%s</a></li>' . "\n\t\t\t\t\t",($tabLabels ? '' : ' class="active"'), $ChildTable, $ChildLookupField, $ChildTable, $ChildLookupField, $TableIcon, $childConfig['tab-label']);
271                         $tabPanels .= sprintf(
'<div id="panel_%s-%s" class="tab-pane%s"><img src="loading.gif" align="top" />%s</div>' . "\n\t\t\t\t", $ChildTable, $ChildLookupField, ($tabPanels ? '' : ' active'), $Translation['Loading ...']);
272                         $tabLoaders .= sprintf(
'post("parent-children.php", { ChildTable: "%s", ChildLookupField: "%s", SelectedID: "%s", Page: 1, SortBy: "", SortDirection: "", Operation: "get-records" }, "panel_%s-%s");' . "\n\t\t\t\t", $ChildTable, $ChildLookupField, addslashes($SelectedID), $ChildTable, $ChildLookupField);
273                     }
274                 }
275             }
276
277             
if(!$tabLabels){ die('<!-- no children of current parent table are accessible to current user -->'); }
278             ?>
279             <div id=
"children-tabs">
280                 <ul
class="nav nav-tabs">
281                     <?php echo $tabLabels; ?>
282                 </ul>
283                 <span id=
"pc-loading"></span>
284             </div>
285             <div
class="tab-content"><?php echo $tabPanels; ?></div>
286
287             <script>
288                 $j(function(){
289                     
/* for iOS, avoid loading child tabs in modals */
290                     
var iOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
291                     
var embedded = ($j('.navbar').length == 0);
292                     
if(iOS && embedded){
293                         $j(
'#children-tabs').next('.tab-content').remove();
294                         $j(
'#children-tabs').remove();
295                         
return;
296                     }
297
298                     
/* ajax loading of each tab's contents */
299                     <?php echo $tabLoaders; ?>
300                 })
301             </script>
302             <?php
303             
break;
304
305         
/************************************************/
306         
case 'show-children-printable':
307             
/* populate HTML and JS content with children buttons */
308             $tabLabels = $tabPanels = $tabLoaders =
'';
309             
foreach($userPCConfig as $ChildTable => $childLookups){
310                 
foreach($childLookups as $ChildLookupField => $childConfig){
311                     
if($childConfig['parent-table'] == $ParentTable){
312                         $TableIcon = ($childConfig[
'table-icon'] ? "<img src=\"{$childConfig['table-icon']}\" border=\"0\" />" : '');
313                         $tabLabels .= sprintf(
'<button type="button" class="btn btn-default" data-target="#panel_%s-%s" id="tab_%s-%s" data-toggle="collapse">%s %s</button>' . "\n\t\t\t\t\t", $ChildTable, $ChildLookupField, $ChildTable, $ChildLookupField, $TableIcon, $childConfig['tab-label']);
314                         $tabPanels .= sprintf(
'<div id="panel_%s-%s" class="collapse"><img src="loading.gif" align="top" />%s</div>' . "\n\t\t\t\t", $ChildTable, $ChildLookupField, $Translation['Loading ...']);
315                         $tabLoaders .= sprintf(
'post("parent-children.php", { ChildTable: "%s", ChildLookupField: "%s", SelectedID: "%s", Page: 1, SortBy: "", SortDirection: "", Operation: "get-records-printable" }, "panel_%s-%s");' . "\n\t\t\t\t", $ChildTable, $ChildLookupField, addslashes($SelectedID), $ChildTable, $ChildLookupField);
316                     }
317                 }
318             }
319
320             
if(!$tabLabels){ die('<!-- no children of current parent table are accessible to current user -->'); }
321             ?>
322             <div id=
"children-tabs" class="hidden-print">
323                 <div
class="btn-group btn-group-lg">
324                     <?php echo $tabLabels; ?>
325                 </div>
326                 <span id=
"pc-loading"></span>
327             </div>
328             <div
class="vspacer-lg"><?php echo $tabPanels; ?></div>
329
330             <script>
331                 $j(function(){
332                     
/* for iOS, avoid loading child tabs in modals */
333                     
var iOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
334                     
var embedded = ($j('.navbar').length == 0);
335                     
if(iOS && embedded){
336                         $j(
'#children-tabs').next('.tab-content').remove();
337                         $j(
'#children-tabs').remove();
338                         
return;
339                     }
340
341                     
/* ajax loading of each tab's contents */
342                     <?php echo $tabLoaders; ?>
343                 })
344             </script>
345             <?php
346             
break;
347
348         
/************************************************/
349         
case 'get-records-printable':
350         
default: /* default is 'get-records' */
351
352             
if($Operation == 'get-records-printable'){
353                 $userPCConfig[$ChildTable][$ChildLookupField][
'records-per-page'] = 2000;
354             }
355
356             
// build the user permissions limiter
357             $permissionsWhere = $permissionsJoin =
'';
358             $permChild = getTablePermissions($ChildTable);
359             
if($permChild[2] == 1){ // user can view only his own records
360                 $permissionsWhere =
"`$ChildTable`.`{$userPCConfig[$ChildTable][$ChildLookupField]['child-primary-key']}`=`membership_userrecords`.`pkValue` AND `membership_userrecords`.`tableName`='$ChildTable' AND LCASE(`membership_userrecords`.`memberID`)='".getLoggedMemberID()."'";
361             }elseif($permChild[
2] == 2){ // user can view only his group's records
362                 $permissionsWhere =
"`$ChildTable`.`{$userPCConfig[$ChildTable][$ChildLookupField]['child-primary-key']}`=`membership_userrecords`.`pkValue` AND `membership_userrecords`.`tableName`='$ChildTable' AND `membership_userrecords`.`groupID`='".getLoggedGroupID()."'";
363             }elseif($permChild[
2] == 3){ // user can view all records
364                 
/* that's the only case remaining ... no need to modify the query in this case */
365             }
366             $permissionsJoin = ($permissionsWhere ?
", `membership_userrecords`" : '');
367
368             
// build the count query
369             $forcedWhere = $userPCConfig[$ChildTable][$ChildLookupField][
'forced-where'];
370             $query =
371                 preg_replace(
'/^select .* from /i', 'SELECT count(1) FROM ', $userPCConfig[$ChildTable][$ChildLookupField]['query']) .
372                 $permissionsJoin .
" WHERE " .
373                 ($permissionsWhere ?
"( $permissionsWhere )" : "( 1=1 )") . " AND " .
374                 ($forcedWhere ?
"( $forcedWhere )" : "( 2=2 )") . " AND " .
375                 
"`$ChildTable`.`$ChildLookupField`='" . makeSafe($SelectedID) . "'";
376             $totalMatches = sqlValue($query);
377
378             
// make sure $Page is <= max pages
379             $maxPage = ceil($totalMatches / $userPCConfig[$ChildTable][$ChildLookupField][
'records-per-page']);
380             
if($Page > $maxPage){ $Page = $maxPage; }
381
382             
// initiate output data array
383             $data = array(
384                 
'config' => $userPCConfig[$ChildTable][$ChildLookupField],
385                 
'parameters' => array(
386                     
'ChildTable' => $ChildTable,
387                     
'ChildLookupField' => $ChildLookupField,
388                     
'SelectedID' => $SelectedID,
389                     
'Page' => $Page,
390                     
'SortBy' => $SortBy,
391                     
'SortDirection' => $SortDirection,
392                     
'Operation' => $Operation
393                 ),
394                 
'records' => array(),
395                 
'totalMatches' => $totalMatches
396             );
397
398             
// build the data query
399             
if($totalMatches){ // if we have at least one record, proceed with fetching data
400                 $startRecord = $userPCConfig[$ChildTable][$ChildLookupField][
'records-per-page'] * ($Page - 1);
401                 $data[
'query'] =
402                     $userPCConfig[$ChildTable][$ChildLookupField][
'query'] .
403                     $permissionsJoin .
" WHERE " .
404                     ($permissionsWhere ?
"( $permissionsWhere )" : "( 1=1 )") . " AND " .
405                     ($forcedWhere ?
"( $forcedWhere )" : "( 2=2 )") . " AND " .
406                     
"`$ChildTable`.`$ChildLookupField`='" . makeSafe($SelectedID) . "'" .
407                     ($SortBy !==
false && $userPCConfig[$ChildTable][$ChildLookupField]['sortable-fields'][$SortBy] ? " ORDER BY {$userPCConfig[$ChildTable][$ChildLookupField]['sortable-fields'][$SortBy]} $SortDirection" : '') .
408                     
" LIMIT $startRecord, {$userPCConfig[$ChildTable][$ChildLookupField]['records-per-page']}";
409                 $res = sql($data[
'query'], $eo);
410                 
while($row = db_fetch_row($res)){
411                     $data[
'records'][$row[$userPCConfig[$ChildTable][$ChildLookupField]['child-primary-key-index']]] = $row;
412                 }
413             }
else{ // if no matching records
414                 $startRecord =
0;
415             }
416
417             
if($Operation == 'get-records-printable'){
418                 $response = loadView($userPCConfig[$ChildTable][$ChildLookupField][
'template-printable'], $data);
419             }
else{
420                 $response = loadView($userPCConfig[$ChildTable][$ChildLookupField][
'template'], $data);
421             }
422
423             
// change name space to ensure uniqueness
424             $uniqueNameSpace = $ChildTable.ucfirst($ChildLookupField).
'GetRecords';
425             echo str_replace(
"{$ChildTable}GetChildrenRecordsList", $uniqueNameSpace, $response);
426         
/************************************************/
427     }



Hệ thống xếp lịch học tín chỉ cho sinh viên CNTT trên PHP & MySQL 111.086 lượt xem

Gõ tìm kiếm nhanh...